﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<DTO.Models.MEDIA>>" %>

<% 
    string domaincms = ConfigurationManager.AppSettings["domaincms"];
    foreach (var item in Model) { 
%>

<div class="dung-item">
	<div class="dung-col2 dung-other1 dung-left dung-text-center">
		<a href='<%= Url.Content("~/Hoatdong/Detail/" + item.MediaID + "?typeMediaName=" + ViewData["TypeMediaName"] + "&pageIndex=" + ViewData["PageIndex"]) %>'><img src='<%= Html.Encode(domaincms + "/MediaImage/" + item.ID.ToString() + ".jpg") %>' width="100%" height="100" alt="" /></a>
	</div>
	<div class="dung-col2 dung-other2 dung-right">
		<p>
			<b class="dung-larger"><a href="#"><%= Html.ActionLink(item.Title, "Detail", "Hoatdong", new {ID = item.MediaID, typeMediaName = ViewData["TypeMediaName"], pageIndex = ViewData["PageIndex"]}, null) %></a></b>
			<br/>
            <span class="dung-small">Ngày tạo <%= Html.Encode(string.Format("{0:dd/MM/yyyy H:mm:ss tt}", item.DateCreate)) %></span>
            <br />
			<span class="dung-small">Ngày cập nhật <%= Html.Encode(string.Format("{0:dd/MM/yyyy H:mm:ss tt}", item.DateModify)) %></span>
		</p>
		<p><%= Html.Encode(item.Intro) %></p>
		<p class="dung-text-right"><%= Html.ActionLink("Chi tiết >>", "Detail", "Hoatdong", new { ID = item.MediaID, typeMediaName = ViewData["TypeMediaName"], pageIndex = ViewData["PageIndex"] }, null)%></p>
	</div>
	<div class="clearer">&nbsp;</div>
</div>
       
<%} %>

					
<div class="dung-text-right">
	
    <% 
        int totalpage = Convert.ToInt32(ViewData["TotalPage"]);
        int pageindex = Convert.ToInt32(ViewData["PageIndex"]);
        int pagesize = Convert.ToInt32(ViewData["PageSize"]);
        
            
        int th = pageindex / pagesize;
        int begin = 1;
        int max = totalpage;
        if(th - 1 > 0)
        {
            begin = (th - 1) * pagesize;
        }
        if((th + 1) * pagesize < totalpage)
        {
            max = (th + 1) * pagesize;   
        }
    %>
    <% Response.Write("<span>&nbsp;</span><b><a onclick='loadmediapage(" + 1 + ")'>|<</a></b><span>&nbsp;</span>");%>
    <%    
        for(int index = begin; index <= max; index++)
        {
            if(index != pageindex)
            {
                if((index == begin && index % pagesize == 0) || (index == max && index % pagesize == 0))
                {
                    %>
                    <% Response.Write("<span>&nbsp;</span><b><a onclick='loadmediapage(" + index.ToString() + ")'>...</a></b><span>&nbsp;</span>"); %>
                    <%
                }
                else
                {
                    %>
                    <% Response.Write("<span>&nbsp;</span><b><a onclick='loadmediapage(" + index.ToString() + ")'>" + index.ToString() + "</a></b><span>&nbsp;</span>"); %>
                    <%
                }
            }    
            else
            {
                %>
                <% Response.Write("<span>&nbsp;</span><b><a class='paging-selected' onclick='loadmediapage(" + index.ToString() + ")'>" + index.ToString() + "</a></b><span>&nbsp;</span>"); %>
                <%
            }
        }
    %>
	<% Response.Write("<span>&nbsp;</span><b><a onclick='loadmediapage(" + (totalpage).ToString() + ")'>>|</a></b><span>&nbsp;</span>");%>
    

</div>

<script type="text/javascript">

    function loadmediapage(pageindex) {
        $.get("/Hoatdong/List/"+ "<%= ViewData["TypeMediaName"] %>" +"?pPageIndex=" + pageindex + "", 
            function (data) {
                $('#hoatdonglist').fadeOut();
                $('#hoatdonglist').html(data);
                $('#hoatdonglist').fadeIn();
            }
        );
    }
</script>